<!DOCTYPE HTML>
<html>
    <head>
        <meta charset="utf-8" />
        <title>文章投稿-{eyou:global name='web_name' /}</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
        <link href="{eyou:global name='web_cmspath'/}/favicon.ico" rel="shortcut icon" type="image/x-icon" />
        {eyou:static file="users/skin/css/basic.css"/}
        {eyou:static file="users/skin/css/eyoucms.css"/}
        <!-- 新样式 2020-12-8 -->
        {eyou:static file="users/skin/css/element/index.css" /}
        {eyou:static file="users/skin/css/e-user.css" /}
        {eyou:include file="users/skin/css/diy_css.htm"/}
        {eyou:static file="/public/plugins/layui/css/layui.css" /}
        {eyou:static file="/public/static/common/js/jquery.min.js"/}
        {eyou:static file="/public/plugins/layer-v3.1.0/layer.js"/}
        {eyou:static file="/public/static/common/js/tag_global.js"/}
        {eyou:static file="/public/static/common/js/mobile_global.js"/}
    </head>

    <body>
        <script type="text/javascript">
            var eyou_basefile = "{$Request.baseFile}";
            window.UEDITOR_HOME_URL = "__ROOT_DIR__/public/plugins/Ueditor/";
            var type20210507 = '';//下载模型的上传类型
            var attr_field20210507 = '';//下载模型的attr_field
            var servername_use20210507 = '';//下载模型的servername_use
            var default_servername20210507 = '';//下载模型的default_servername
        </script>
        {eyou:static file="/public/plugins/Ueditor/ueditor.config.js"/}
        {eyou:static file="/public/plugins/Ueditor/ueditor.all.min.js"/}
        {eyou:static file="/public/plugins/Ueditor/lang/zh-cn/zh-cn.js"/}
        {eyou:static file="/public/plugins/laydate/laydate.js"/}
        {eyou:static file="/public/plugins/layui/layui.js" /}
        <div class="ey-header-status">
            <div class="header-status-l">
                <a href="javascript:history.go(-1);"><i class="el-icon-arrow-left"></i></a>
            </div> 
            <div class="header-status-m">{$MenuTitle}</div> 
            <div class="header-status-r">
                <a href="{eyou:url link='user/Users/index' /}"><i class="el-icon-user"></i></a>
            </div>
        </div>
        <div class="h50"></div>

        <div class="ey-container">
            <form id="post_form">
                <input type="hidden" name="channel" value="0">
                <div class="ey-con ey-row bgfff">
                    <!-- 公共字段 -->
                    <div class="item-from-flex">
                        <div class="item-flex-l">
                            <div class="item-tit">文章标题 <span class="red">*</span></div>
                            <div class="item-con">
                                <input type="text" name="title" id="title" class="input-text" maxlength="100" placeholder="请输入文章标题">
                            </div>
                        </div>
                    </div>

                    <div class="item-from-flex">
                        <div class="item-flex-l">
                            <div class="item-tit">所属栏目 <span class="red">*</span></div>
                            <div class="item-con">
                                <div class="select">
                                    {$arctype_html}
                                </div>
                            </div>
                        </div>
                        <div class="item-flex-r"> <i class="el-icon-arrow-right"></i> </div>
                    </div>

                    <div class="item-from-flex">
                        <div class="item-flex-l">
                            <div class="item-tit">TAG标签</div>
                            <div class="item-con">
                                <input type="text" name="tags" id="tags" class="input-text" placeholder="多个标签之间用逗号隔开">
                            </div>
                        </div>
                    </div>

                    <div class="item-from-flex" id="openLitpic" {empty name='$is_litpic_users_release' value='1'} style="display: none;" {/empty}>
                        <div class="item-flex-l">
                            <div class="item-tit">缩略图</div>
                            <div class="item-con">
                                <div class="item-flex-img">
                                    <a href="javascript:void(0);" onclick="$('#litpicOnclick').trigger('click');" class="img-upload" title="点击上传">
                                        <div class="y-line" id="litpicYline"></div>
                                        <div class="x-line" id="litpicXline"></div>
                                        <img src="" id="litpicImgSrc">
                                    </a>
                                    <input type="hidden" name="litpic_inpiut" id="litpicInpiut">
                                    <input type="file" name="litpic_inpiut_file" id="litpicOnclick" onchange="litpicOnclickFile(this);" style="display: none;">
                                    <!-- <span id="litpicSpan" style="cursor: pointer; display: none;" onclick="$('#litpicOnclick').trigger('click');">修改</span> -->
                                </div>
                            </div>
                        </div>
                        <script type="text/javascript">
                            function litpicOnclickFile(obj) {
                                var file = $(obj)[0].files[0];
                                if (!file) return false;
                                var formData = new FormData();
                                formData.append('_ajax', 1);
                                formData.append('file', file);
                                formData.append('compress', '1000-1000');
                                showLayerLoad();
                                $.ajax({
                                    type: 'post',
                                    url: eyou_basefile + "?m=user&c=Uploadify&a=imageUp",
                                    data: formData,
                                    contentType: false,
                                    processData: false,
                                    dataType: 'json',
                                    success: function (res) {
                                        layer.closeAll();
                                        if (res.state == 'SUCCESS') {
                                            // $('#litpicSpan').show();
                                            $("#litpicInpiut").val(res.url);
                                            $('#litpicYline, #litpicXline').hide();
                                            $("#litpicImgSrc").attr('src', res.url);
                                        } else {
                                            showErrorAlert(res.state);
                                        }
                                    },
                                    error: function(e) {
                                        layer.closeAll();
                                        showErrorAlert(e.responseText);
                                    }
                                })
                            }
                        </script>
                    </div>

                    <!--下载模型特定字段-->
                    <div style="display: none;" id="downloadModel">
                        {eyou:include file="users/article_download_add.htm" /}
                    </div>

                    <!--视频模型特定字段-->
                    <div style="display: none;" id="mediaModel">
                        {eyou:include file="users/article_media_add.htm" /}
                    </div>

                    <!-- 图集模型特定字段 -->
                    <div style="display: none;" id="imagesModel">
                        {eyou:include file="users/article_images_add.htm" /}
                    </div>

                    <!-- 模型自定义字段 -->
                    <span id="FieldAddonextitem"></span>
                    <script type="text/javascript">
                        $(function() {
                            // 默认执行选中栏目
                            var typeid = {$typeid|default='0'};
                            if (0 === parseInt(typeid)) typeid = $('#typeid').find('option:selected').val();
                            getAddonextitem(0, typeid);

                            // 切换执行选中栏目
                            $('#typeid').change(function() {
                                getAddonextitem(1, $(this).val());
                            });
                        });

                        function getAddonextitem(init, typeid) {
                            // 设置选中栏目的模型ID
                            var channel = $("#typeid option:selected").attr('data-channel');
                            $("input[name='channel']").val(channel);

                            // 模型字段隐藏、显示处理
                            $("#mediaModel").hide();
                            $("#imagesModel").hide();
                            $("#downloadModel").hide();
                            if (3 === parseInt(channel)) {
                                // 图集模型特定字段
                                $("#imagesModel").show();
                            } else if (4 === parseInt(channel)) {
                                // 下载模型特定字段
                                $("#downloadModel").show();
                            } else if (5 === parseInt(channel)) {
                                // 视频特定模型字段
                                $("#mediaModel").show();
                            }

                            // 操作提示
                            showLayerLoad();
                            $.ajax({
                                url : "{:url('user/UsersRelease/get_addonextitem')}",
                                data: {typeid: typeid, channel: channel, _ajax: 1},
                                type: 'post',
                                success: function(res) {
                                    layer.closeAll();
                                    if (0 === parseInt(res.code)) {
                                        showErrorAlert(res.msg);
                                    } else {
                                        // 缩略图隐藏、显示处理
                                        $('#openLitpic').hide();
                                        if (res.data.is_litpic_users_release) $('#openLitpic').show();

                                        // 模型自定义字段加载
                                        $('#FieldAddonextitem').empty().html(res.data.html);

                                        // 渲染编辑器
                                        if (1 === parseInt(init)) {
                                            $.each(res.data.htmltextField, function (index, value) {
                                                showEditor_1597892187('addonFieldExt_'+value);
                                            });
                                        }

                                        // 下载模型特定处理
                                        if (4 === parseInt(channel)) {
                                            var download = res.data.download;
                                            var users_level_html = '<option value="0" selected>不限会员</option>';
                                            $.each(download.users_level, function (index, value) {
                                                users_level_html += '<option value="'+value.level_id+'">'+value.level_name+'</option>\n';
                                            });
                                            $('#arc_level_id').html(users_level_html);
                                            if ('local' != download.upload_flag) {
                                                // 第三方
                                                var upload_button_html = '<button type="button" class="layui-btn layui-btn-normal" style="position: relative;z-index: 1;">\n' + download.upload_flag + '选择多文件\n<input type="file" name="file" id="' + download.upload_flag + 'File" multiple="multiple" onchange="' + download.upload_flag + '_download__upload(this);" style="position: absolute; top: 0; right: 0; opacity: 0; width: 110px; height: 30px;"/>\n</button>';
                                                $('#download-layui-upload').prepend(upload_button_html);
                                            } else {
                                                $("#buttonList").show();
                                            }
                                            $('#download-layui-upload').attr('data-type', download.upload_flag);
                                            if (1 === parseInt(download.servername_use)) $(".th_server_name").show();
                                            type20210507 = download.basic.file_type;
                                            attr_field20210507 = download.attr_field;
                                            servername_use20210507 = download.servername_use;
                                            default_servername20210507 = download.default_servername;
                                        }
                                    }
                                },
                                error: function(e){
                                    layer.closeAll();
                                    showErrorAlert(e.responseText);
                                }
                            });
                        }
                    </script>
                </div>
                <div class="h50"></div>
                {$TokenValue}
                <div class="public-btn">
                    <a href="JavaScript:void(0);" data-url="{:url('UsersRelease/article_add', ['_ajax'=>1])}" onclick="addArticle(this);">立即发布</a>
                </div>
            </form>
        </div>

        <script type="text/javascript">
            // 去除 select中值相同的option(去重)，配合{$arctype_html}使用
            $(function() {
                $("#typeid option").each(function() {
                    var val = $(this).val();
                    if ($("#typeid option[value='" + val + "']").length > 1) $("#typeid option[value='" + val + "']:eq(0)").remove();
                });
            });

            function addArticle(obj) {
                if (!$('#title').val()) {
                    showLayerMsg('请填写文章标题');
                    $('#title').focus();
                    return false;
                }
                if (0 === parseInt($('#typeid').val())) {
                    showLayerMsg('请选择所属栏目');
                    $('#typeid').focus();
                    return false;
                }
                // 视频模型处理视频地址
                var channel = $("#typeid option:selected").attr('data-channel');
                $("input[name='channel']").val(channel);
                if (5 === parseInt(channel)) urlToStr();

                showLayerLoad();
                $.ajax({
                    url : $(obj).attr('data-url'),
                    data: $('#post_form').serialize(),
                    type: 'post',
                    dataType: 'json',
                    success: function(res) {
                        layer.closeAll();
                        if (1 == res.code) {
                            if (res.data.email) eyUnifiedSendRemind(res.data.email);
                            if (res.data.mobile) eyUnifiedSendRemind(res.data.mobile);
                            showLayerMsg(res.msg, 2, function() {
                                window.location.href = res.url;
                            });
                        } else {
                            showLayerMsg(res.msg);
                            if (res.data) $('#'+res.data).focus(); 
                        }
                    },
                    error: function(e) {
                        layer.closeAll();
                        showErrorAlert(e.responseText);
                    }
                });
            }
        </script>
    </body>
</html>